const { User } = require('../../model/user');
const bcrypt = require('bcrypt');
module.exports = async (req, res, next) => {
    let id = req.query.id;
    const { username, password, email, state, role } = req.body;
    let user = await User.findOne({ _id: id });
    const isEqual = await bcrypt.compare(password, user.password);
    if (isEqual) {
        await User.updateOne({ _id: id }, {
            username: username,
            email: email,
            role: role,
            state: state,
        })
        res.redirect('/admin/user');
    } else {
        let obj = { path: '/admin/user-edit', message: '密码比对错误，修改失败', id: id };
        next(JSON.stringify(obj));
    }
}